<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title>CENTOS 安装MySQL - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="CENTOS 安装MySQL">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content="CENTOS 安装MySQL - 天地维杰网" />
    <meta name="description" content="CENTOS 安装MySQL" />
     
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/install-mysql-on-centos/" itemprop="url">
        CENTOS 安装MySQL
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2022-07-12">
    2022-07-12
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/linux" itemprop="url" rel="index">
        <span itemprop="name">linux</span>
      </a>
      &nbsp; 
    </span>
  
</span>


      
 <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">原创</span>
</span>

       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">1214 字 ~3分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    

    <p>CENTOS 版本 <code>7.3</code></p>

<p>MYSQL 版本：<code>5.7.29</code></p>

<p>下载地址：<code>https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz</code></p>

<p>将下载好的安装压缩包解压到<code>/usr/local</code>目录下。<font color=red>PS:初次安装者建议先在/usr/local中操作，熟练以后再自定义到其他目录，因为有很多东西要改的，被目录影响会很不好进行下去</font></p>

<p>解压 mysql包到<code>/usr/local</code>目录</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">tar -vzxf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz</code></pre></div>
<p>创建安装包目录的软链</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">ln -s mysql-5.7.29-linux-glibc2.12-x86_64 mysql</code></pre></div>
<p>为centos添加mysql用户组和mysql用户(-s /bin/false参数指定mysql用户仅拥有所有权，而没有登录权限)</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">groupadd mysql
useradd -r -g mysql -s /bin/false mysql</code></pre></div>
<p>进入mysql目录并为mysql用户赋权</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#204a87">cd</span> /usr/local/mysql
chown -R mysql:mysql ./</code></pre></div>
<p>安装mysql</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"> ./bin/mysqld --user<span style="color:#ce5c00;font-weight:bold">=</span>mysql --basedir<span style="color:#ce5c00;font-weight:bold">=</span>/usr/local/mysql --datadir<span style="color:#ce5c00;font-weight:bold">=</span>/usr/local/mysql/data --initialize</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize</span>

……省略……
2022-07-12T03:27:31.727756Z <span style="color:#0000cf;font-weight:bold">1</span> <span style="color:#ce5c00;font-weight:bold">[</span>Note<span style="color:#ce5c00;font-weight:bold">]</span> A temporary password is generated <span style="color:#204a87;font-weight:bold">for</span> root@localhost: yZho-p8Zsmuv
<span style="color:#8f5902;font-style:italic"># 命令输出中有生成的临时密码: yZho-p8Zsmuv</span></code></pre></div>
<p>启动mysql</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">./support-files/mysql.server start</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># ./support-files/mysql.server start</span>
Starting MySQL.2022-07-12T03:28:10.588141Z mysqld_safe error: log-error <span style="color:#204a87">set</span> to <span style="color:#4e9a06">&#39;/var/log/mariadb/mariadb.log&#39;</span>, however file don<span style="color:#4e9a06">&#39;t exists. Create writable for user &#39;</span>mysql<span style="color:#a40000">&#39;</span>.
 ERROR! The server quit without updating PID file <span style="color:#ce5c00;font-weight:bold">(</span>/var/lib/mysql/db-7-51.pid<span style="color:#ce5c00;font-weight:bold">)</span>.</code></pre></div>
<p>报错没有日志文件，创建目录及文件后再次启动。新报错没有<code>/var/lib/mysql/db-7-51.pid</code>文件</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># mkdir -p /var/log/mariadb/</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># touch /var/log/mariadb/mariadb.log</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># chown mysql:mysql /var/log/mariadb/mariadb.log</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># ./support-files/mysql.server start</span>
Starting MySQL.2022-07-12T03:29:34.161359Z mysqld_safe Directory <span style="color:#4e9a06">&#39;/var/lib/mysql&#39;</span> <span style="color:#204a87;font-weight:bold">for</span> UNIX socket file don<span style="color:#a40000">&#39;</span>t exists.
 ERROR! The server quit without updating PID file <span style="color:#ce5c00;font-weight:bold">(</span>/var/lib/mysql/db-7-51.pid<span style="color:#ce5c00;font-weight:bold">)</span>.</code></pre></div>
<p>查看/var/log/mariadb/mariadb.log日志文件</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">2022-07-12T03:30:04.916037Z 0 [ERROR] Can&#39;t open the mysql.plugin table. Please run mysql_upgrade to create it.
……
2022-07-12T03:30:05.591286Z 0 [ERROR] Fatal error: Can&#39;t open and lock privilege tables: Table &#39;mysql.user&#39; doesn&#39;t exist
2022-07-12T03:30:05.591295Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
2022-07-12T03:30:05.591331Z 0 [ERROR] Aborting</code></pre></div>
<p>修改mysql 配置文件</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">vim /etc/my.cnf

<span style="color:#8f5902;font-style:italic"># 将以下配置复制到my.cnf</span>

<span style="color:#ce5c00;font-weight:bold">[</span>mysqld<span style="color:#ce5c00;font-weight:bold">]</span>
<span style="color:#000">basedir</span><span style="color:#ce5c00;font-weight:bold">=</span>/usr/local/mysql
<span style="color:#000">datadir</span><span style="color:#ce5c00;font-weight:bold">=</span>/usr/local/mysql/data
<span style="color:#000">port</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#0000cf;font-weight:bold">3306</span>
<span style="color:#000">socket</span><span style="color:#ce5c00;font-weight:bold">=</span>/tmp/mysql.sock
 
symbolic-links<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">0</span>
log-error<span style="color:#ce5c00;font-weight:bold">=</span>/var/log/mysqld.log
pid-file<span style="color:#ce5c00;font-weight:bold">=</span>/tmp/mysqld/mysqld.pid
<span style="color:#000">sql_mode</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#39;STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION&#39;</span>
<span style="color:#ce5c00;font-weight:bold">[</span>client<span style="color:#ce5c00;font-weight:bold">]</span>
default-character-set<span style="color:#ce5c00;font-weight:bold">=</span>utf8
 
<span style="color:#ce5c00;font-weight:bold">[</span>mysql<span style="color:#ce5c00;font-weight:bold">]</span>
default-character-set<span style="color:#ce5c00;font-weight:bold">=</span>utf8
 
<span style="color:#ce5c00;font-weight:bold">[</span>mysqld<span style="color:#ce5c00;font-weight:bold">]</span>
log-bin<span style="color:#ce5c00;font-weight:bold">=</span>mysql-bin 
binlog-format<span style="color:#ce5c00;font-weight:bold">=</span>ROW 
<span style="color:#000">server_id</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">1</span> 
<span style="color:#000">max_connections</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">1000</span>
 
<span style="color:#000">init_connect</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#39;SET collation_connection = utf8_unicode_ci&#39;</span>
<span style="color:#000">init_connect</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#39;SET NAMES utf8&#39;</span>
character-set-server<span style="color:#ce5c00;font-weight:bold">=</span>utf8
collation-server<span style="color:#ce5c00;font-weight:bold">=</span>utf8_unicode_ci
skip-character-set-client-handshake</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># mkdir -p /tmp/mysqld/</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># touch /tmp/mysqld/mysqld.pid</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># chown -R mysql:mysql /tmp/mysqld/</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># chmod 777 /tmp/mysqld/mysqld.pid</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># chown -R mysql:mysql /var/log</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># chmod 777 /var/log/mysqld.log</span></code></pre></div>
<p>然后再次启动mysql，启动成功</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># ./support-files/mysql.server start</span>
Starting MySQL. SUCCESS!</code></pre></div>
<p>复制启动命令到 <code>/etc/init.d/mysql</code>，以后就可以使用  <code>service mysql start</code>启动mysql。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span>cp support-files/mysql.server /etc/init.d/mysql</code></pre></div>
<p>将mysql的指令映射到 <code>/usr/bin</code>目录下，就可以直接用<code>mysql</code>命令登录了。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span> ln -s  /usr/local/mysql/bin/mysql    /usr/bin</code></pre></div>
<p>使用刚刚安装mysql得到的初始化密码进行登录</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">[</span>root@db-7-51 mysql<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># mysql -uroot -pyZho-p8Zsmuv</span>
mysql: <span style="color:#ce5c00;font-weight:bold">[</span>Warning<span style="color:#ce5c00;font-weight:bold">]</span> Using a password on the <span style="color:#204a87">command</span> line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with <span style="color:#000;font-weight:bold">;</span> or <span style="color:#4e9a06">\g</span>.
Your MySQL connection id is <span style="color:#0000cf;font-weight:bold">4</span>
Server version: 5.7.29-log

Copyright <span style="color:#ce5c00;font-weight:bold">(</span>c<span style="color:#ce5c00;font-weight:bold">)</span> 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type <span style="color:#4e9a06">&#39;help;&#39;</span> or <span style="color:#4e9a06">&#39;\h&#39;</span> <span style="color:#204a87;font-weight:bold">for</span> help. Type <span style="color:#4e9a06">&#39;\c&#39;</span> to clear the current input statement.</code></pre></div>
<p>但执行mysql命令时报如下错误，需要修改密码使用</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sql" data-lang="sql"><span style="color:#000">mysql</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#204a87;font-weight:bold">show</span> <span style="color:#000">databases</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">ERROR</span> <span style="color:#0000cf;font-weight:bold">1820</span> <span style="color:#000;font-weight:bold">(</span><span style="color:#000">HY000</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000">You</span> <span style="color:#000">must</span> <span style="color:#204a87;font-weight:bold">reset</span> <span style="color:#000">your</span> <span style="color:#000">password</span> <span style="color:#204a87;font-weight:bold">using</span> <span style="color:#204a87;font-weight:bold">ALTER</span> <span style="color:#204a87;font-weight:bold">USER</span> <span style="color:#204a87;font-weight:bold">statement</span> <span style="color:#204a87;font-weight:bold">before</span> <span style="color:#000">executing</span> <span style="color:#000">this</span> <span style="color:#204a87;font-weight:bold">statement</span><span style="color:#000;font-weight:bold">.</span>
<span style="color:#ce5c00;font-weight:bold">#</span> <span style="color:#a40000">修</span><span style="color:#a40000">改</span><span style="color:#a40000">密</span><span style="color:#a40000">码</span><span style="color:#a40000">为</span> <span style="color:#0000cf;font-weight:bold">123456</span>
<span style="color:#000">mysql</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#204a87;font-weight:bold">set</span> <span style="color:#000">password</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">password</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">123456</span><span style="color:#4e9a06">&#39;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">Query</span> <span style="color:#000">OK</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#204a87;font-weight:bold">rows</span> <span style="color:#000">affected</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#0000cf;font-weight:bold">1</span> <span style="color:#000">warning</span> <span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">.</span><span style="color:#0000cf;font-weight:bold">01</span> <span style="color:#000">sec</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#ce5c00;font-weight:bold">#</span> <span style="color:#a40000">设</span><span style="color:#a40000">置</span><span style="color:#a40000">密</span><span style="color:#a40000">码</span><span style="color:#a40000">有</span><span style="color:#a40000">效</span><span style="color:#a40000">期</span><span style="color:#a40000">永</span><span style="color:#a40000">不</span><span style="color:#a40000">过</span><span style="color:#a40000">期</span>
<span style="color:#000">mysql</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#204a87;font-weight:bold">alter</span> <span style="color:#204a87;font-weight:bold">user</span> <span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">root</span><span style="color:#4e9a06">&#39;</span><span style="color:#ce5c00;font-weight:bold">@</span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">localhost</span><span style="color:#4e9a06">&#39;</span> <span style="color:#000">password</span> <span style="color:#000">expire</span> <span style="color:#000">never</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">Query</span> <span style="color:#000">OK</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#204a87;font-weight:bold">rows</span> <span style="color:#000">affected</span> <span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">.</span><span style="color:#0000cf;font-weight:bold">00</span> <span style="color:#000">sec</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#ce5c00;font-weight:bold">#</span> <span style="color:#a40000">应</span><span style="color:#a40000">用</span><span style="color:#a40000">修</span><span style="color:#a40000">改</span>
<span style="color:#000">mysql</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000">flush</span> <span style="color:#204a87;font-weight:bold">privileges</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">Query</span> <span style="color:#000">OK</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#204a87;font-weight:bold">rows</span> <span style="color:#000">affected</span> <span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">.</span><span style="color:#0000cf;font-weight:bold">00</span> <span style="color:#000">sec</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#ce5c00;font-weight:bold">#</span> <span style="color:#a40000">修</span><span style="color:#a40000">改</span><span style="color:#a40000">后</span><span style="color:#a40000">可</span><span style="color:#a40000">以</span><span style="color:#a40000">使</span><span style="color:#a40000">用</span><span style="color:#a40000">新</span><span style="color:#a40000">密</span><span style="color:#a40000">码</span><span style="color:#a40000">重</span><span style="color:#a40000">新</span><span style="color:#a40000">登</span><span style="color:#a40000">录</span><span style="color:#a40000">，</span><span style="color:#a40000">可</span><span style="color:#a40000">以</span><span style="color:#a40000">正</span><span style="color:#a40000">常</span><span style="color:#a40000">执</span><span style="color:#a40000">行</span><span style="color:#a40000">命</span><span style="color:#a40000">令</span>

<span style="color:#000;font-weight:bold">[</span><span style="color:#000">root</span><span style="color:#ce5c00;font-weight:bold">@</span><span style="color:#000">db</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#0000cf;font-weight:bold">7</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#0000cf;font-weight:bold">51</span> <span style="color:#000">mysql</span><span style="color:#000;font-weight:bold">]</span><span style="color:#ce5c00;font-weight:bold">#</span> <span style="color:#000">mysql</span> <span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">uroot</span> <span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">p123456</span>
<span style="color:#000">mysql</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">[</span><span style="color:#000">Warning</span><span style="color:#000;font-weight:bold">]</span> <span style="color:#204a87;font-weight:bold">Using</span> <span style="color:#000">a</span> <span style="color:#000">password</span> <span style="color:#204a87;font-weight:bold">on</span> <span style="color:#000">the</span> <span style="color:#000">command</span> <span style="color:#000">line</span> <span style="color:#000">interface</span> <span style="color:#000">can</span> <span style="color:#000">be</span> <span style="color:#000">insecure</span><span style="color:#000;font-weight:bold">.</span>
<span style="color:#000">Welcome</span> <span style="color:#204a87;font-weight:bold">to</span> <span style="color:#000">the</span> <span style="color:#000">MySQL</span> <span style="color:#000">monitor</span><span style="color:#000;font-weight:bold">.</span>  <span style="color:#000">Commands</span> <span style="color:#204a87;font-weight:bold">end</span> <span style="color:#204a87;font-weight:bold">with</span> <span style="color:#000;font-weight:bold">;</span> <span style="color:#204a87;font-weight:bold">or</span> <span style="color:#a40000">\</span><span style="color:#204a87;font-weight:bold">g</span><span style="color:#000;font-weight:bold">.</span>
<span style="color:#000">Your</span> <span style="color:#000">MySQL</span> <span style="color:#204a87;font-weight:bold">connection</span> <span style="color:#000">id</span> <span style="color:#204a87;font-weight:bold">is</span> <span style="color:#0000cf;font-weight:bold">5</span>
<span style="color:#000">Server</span> <span style="color:#204a87;font-weight:bold">version</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">5</span><span style="color:#000;font-weight:bold">.</span><span style="color:#0000cf;font-weight:bold">7</span><span style="color:#000;font-weight:bold">.</span><span style="color:#0000cf;font-weight:bold">29</span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#000">log</span> <span style="color:#000">MySQL</span> <span style="color:#000">Community</span> <span style="color:#000">Server</span> <span style="color:#000;font-weight:bold">(</span><span style="color:#000">GPL</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#000">Copyright</span> <span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">c</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">2000</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#0000cf;font-weight:bold">2020</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">Oracle</span> <span style="color:#204a87;font-weight:bold">and</span><span style="color:#ce5c00;font-weight:bold">/</span><span style="color:#204a87;font-weight:bold">or</span> <span style="color:#000">its</span> <span style="color:#000">affiliates</span><span style="color:#000;font-weight:bold">.</span> <span style="color:#204a87;font-weight:bold">All</span> <span style="color:#000">rights</span> <span style="color:#000">reserved</span><span style="color:#000;font-weight:bold">.</span>

<span style="color:#000">Oracle</span> <span style="color:#204a87;font-weight:bold">is</span> <span style="color:#000">a</span> <span style="color:#000">registered</span> <span style="color:#000">trademark</span> <span style="color:#204a87;font-weight:bold">of</span> <span style="color:#000">Oracle</span> <span style="color:#000">Corporation</span> <span style="color:#204a87;font-weight:bold">and</span><span style="color:#ce5c00;font-weight:bold">/</span><span style="color:#204a87;font-weight:bold">or</span> <span style="color:#000">its</span>
<span style="color:#000">affiliates</span><span style="color:#000;font-weight:bold">.</span> <span style="color:#000">Other</span> <span style="color:#204a87;font-weight:bold">names</span> <span style="color:#000">may</span> <span style="color:#000">be</span> <span style="color:#000">trademarks</span> <span style="color:#204a87;font-weight:bold">of</span> <span style="color:#000">their</span> <span style="color:#000">respective</span>
<span style="color:#000">owners</span><span style="color:#000;font-weight:bold">.</span>

<span style="color:#204a87;font-weight:bold">Type</span> <span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">help;</span><span style="color:#4e9a06">&#39;</span> <span style="color:#204a87;font-weight:bold">or</span> <span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">\h</span><span style="color:#4e9a06">&#39;</span> <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#000">help</span><span style="color:#000;font-weight:bold">.</span> <span style="color:#204a87;font-weight:bold">Type</span> <span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">\c</span><span style="color:#4e9a06">&#39;</span> <span style="color:#204a87;font-weight:bold">to</span> <span style="color:#000">clear</span> <span style="color:#000">the</span> <span style="color:#204a87;font-weight:bold">current</span> <span style="color:#204a87;font-weight:bold">input</span> <span style="color:#204a87;font-weight:bold">statement</span><span style="color:#000;font-weight:bold">.</span>

<span style="color:#000">mysql</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#204a87;font-weight:bold">show</span> <span style="color:#000">databases</span>
    <span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#ce5c00;font-weight:bold">&gt;</span> <span style="color:#000;font-weight:bold">;</span>
<span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#8f5902;font-style:italic">--------------------+
</span><span style="color:#8f5902;font-style:italic"></span><span style="color:#ce5c00;font-weight:bold">|</span> <span style="color:#204a87;font-weight:bold">Database</span>           <span style="color:#ce5c00;font-weight:bold">|</span>
<span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#8f5902;font-style:italic">--------------------+
</span><span style="color:#8f5902;font-style:italic"></span><span style="color:#ce5c00;font-weight:bold">|</span> <span style="color:#000">information_schema</span> <span style="color:#ce5c00;font-weight:bold">|</span>
<span style="color:#ce5c00;font-weight:bold">|</span> <span style="color:#000">mysql</span>              <span style="color:#ce5c00;font-weight:bold">|</span>
<span style="color:#ce5c00;font-weight:bold">|</span> <span style="color:#000">performance_schema</span> <span style="color:#ce5c00;font-weight:bold">|</span>
<span style="color:#ce5c00;font-weight:bold">|</span> <span style="color:#000">sys</span>                <span style="color:#ce5c00;font-weight:bold">|</span>
<span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#8f5902;font-style:italic">--------------------+</span></code></pre></div>
<p>设置root用户允许远程登录</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sql" data-lang="sql"><span style="color:#ce5c00;font-weight:bold">#</span> <span style="color:#a40000">支</span><span style="color:#a40000">持</span><span style="color:#000">root用户允许远程连接mysql数据库</span>
<span style="color:#204a87;font-weight:bold">grant</span> <span style="color:#204a87;font-weight:bold">all</span> <span style="color:#204a87;font-weight:bold">privileges</span> <span style="color:#204a87;font-weight:bold">on</span> <span style="color:#ce5c00;font-weight:bold">*</span><span style="color:#000;font-weight:bold">.</span><span style="color:#ce5c00;font-weight:bold">*</span> <span style="color:#204a87;font-weight:bold">to</span> <span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">root</span><span style="color:#4e9a06">&#39;</span><span style="color:#ce5c00;font-weight:bold">@</span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">%</span><span style="color:#4e9a06">&#39;</span> <span style="color:#000">identified</span> <span style="color:#204a87;font-weight:bold">by</span> <span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">123456</span><span style="color:#4e9a06">&#39;</span> <span style="color:#204a87;font-weight:bold">with</span> <span style="color:#204a87;font-weight:bold">grant</span> <span style="color:#204a87;font-weight:bold">option</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">flush</span> <span style="color:#204a87;font-weight:bold">privileges</span><span style="color:#000;font-weight:bold">;</span></code></pre></div>
<p>参考文档：</p>

<ul>
<li><a href="https://blog.csdn.net/dc282614966/article/details/81098074">https://blog.csdn.net/dc282614966/article/details/81098074</a></li>
<li><a href="https://blog.csdn.net/Hdu_lc14015312/article/details/104540429">https://blog.csdn.net/Hdu_lc14015312/article/details/104540429</a></li>
<li><a href="https://www.cnblogs.com/linjiqin/p/5270938.html">https://www.cnblogs.com/linjiqin/p/5270938.html</a></li>
</ul>

    </div>
    <footer class="post-footer">
     
 
<div class="post-tags">     
     
    <a href="http://www.shutdown.cn/tags/centos" rel="tag" title="centos">#centos#</a>
    
    <a href="http://www.shutdown.cn/tags/mysql" rel="tag" title="mysql">#mysql#</a>
    
    <a href="http://www.shutdown.cn/tags/linux" rel="tag" title="linux">#linux#</a>
    
</div>



     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/centos-shasum-command-not-found/" rel="next" title="centos shasum command not found">
        <i class="fa fa-chevron-left"></i> centos shasum command not found
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/redis4.0-improve-aofrewrite-use-pipe/" rel="prev" title="Redis4.0之利用管道优化aofrewrite">
        Redis4.0之利用管道优化aofrewrite <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

  <ul class="sidebar-nav motion-element">
    <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
      文章目录
    </li>
    <li class="sidebar-nav-overview" data-target="site-overview">
      站点概览
    </li>
  </ul>

    <section class="site-overview sidebar-panel ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
<section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
    <div class="post-toc">
        <div class="post-toc-content"></div>
    </div>
</section>

  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>